package com.woniuxy.member.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodskuclient.FoodSkuQueryClient;
import com.woniuxy.food.client.foodspuclient.FoodSpuQueryClient;
import com.woniuxy.food.client.foodtypeclient.FoodTypeQueryClient;
import com.woniuxy.food.client.param.SearchFoodSkuByConditionParam;
import com.woniuxy.food.client.param.SearchFoodSpuByConditionParam;
import com.woniuxy.food.client.param.SearchFoodTypeByConditionParam;
import com.woniuxy.food.client.result.FoodTypeClientDto;
import com.woniuxy.member.app.apiImpl.util.RequestUtil;
import com.woniuxy.member.client.MemberFoodQueryClient;
import com.woniuxy.member.client.param.SearchFoodTypeParam;
import com.woniuxy.member.client.param.SearchSpuParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;
import java.util.List;

@RequestMapping("/member")
@RestController
public class MemberFoodQueryApiImpl implements MemberFoodQueryClient {
    @Autowired
    private FoodSpuQueryClient foodSpuQueryClient;
    @Autowired
    private FoodSkuQueryClient foodSkuQueryClient;
    @Autowired
    private FoodTypeQueryClient foodTypeQueryClient;
    @Log("用户查询该商家spu")
    @Override
    public Result searchAllSpuByStoreId(@Valid SearchSpuParam searchSpuParam) {
        SearchFoodSpuByConditionParam searchFoodSpuByConditionParam = BeanUtil.toBean(searchSpuParam, SearchFoodSpuByConditionParam.class);
        searchFoodSpuByConditionParam.setStoreId(RequestUtil.getStoreId());
        Result result = foodSpuQueryClient.searchFoodSpuByCondition(searchFoodSpuByConditionParam);

        return result;
    }
    @Log("用户通过spuId查询sku")
    @Override
    public Result searchSkuBySpuId(Integer spuId) {
        SearchFoodSkuByConditionParam searchFoodSkuByConditionParam = new SearchFoodSkuByConditionParam();
        searchFoodSkuByConditionParam.setSpuId(spuId);
        searchFoodSkuByConditionParam.setSkuState("NORMAL");
        searchFoodSkuByConditionParam.setStoreId(RequestUtil.getStoreId());
        Result result = foodSkuQueryClient.searchFoodSkuByCondition(searchFoodSkuByConditionParam);

        return result;
    }
    @Log("用户查询菜品类型")
    @Override
    public Result searchFoodType(@Valid SearchFoodTypeParam searchFoodTypeParam) {
        SearchFoodTypeByConditionParam searchFoodTypeByConditionParam = BeanUtil.toBean(searchFoodTypeParam, SearchFoodTypeByConditionParam.class);
        searchFoodTypeByConditionParam.setStoreId(RequestUtil.getStoreId());
        Result<List<FoodTypeClientDto>> listResult = foodTypeQueryClient.searchFoodTypeByCondition(searchFoodTypeByConditionParam);

        return listResult;
    }


}
